<template>
	<view class="tabbar" :style="{ 'padding-bottom': paddingBottomHeight + 'rpx' }">
		<view class="tabbar-item" @click="changeTab('/pages/tab/home')">
			<image class="item-img"  src="/static/tab/home-act.png" v-if="current === 1" mode="aspectFit" />
			<image class="item-img"  src="/static/tab/home.png" v-else  mode="aspectFit" />
			<view class="item-name" :class="{ tabbarActive: current === 1 }">首页</view>
		</view>
		
		<image src="/static/tab/scan.png" mode="aspectFill" class="item-scan" @click="scan" />
		
		<view class="tabbar-item" @click="changeTab('/pages/tab/mine')">
			<image class="item-img"  src="/static/tab/mine-act.png" v-if="current === 2" mode="aspectFit" />
			<image class="item-img"  src="/static/tab/mine.png" v-else  mode="aspectFit" />
			<view class="item-name" :class="{ tabbarActive: current === 2 }">我的</view>
		</view>
		
		<!-- <uni-popup ref="bindtoast" type="center">
			<view class="popup-modal">
				<view class="info">确认绑定该好友？</view>
				<view class="flex">
					<view class="f1 close" @click="close('toast')">取消</view>
					<view class="f1" @click="addFriends(info)">确认</view>
				</view>
			</view>
		</uni-popup> -->
	</view>
</template>

<script>
	export default {
		name:"tabbar",
		props: {
			current: {
				type: Number,
				default: 1
			}
		},
		data() {
			return {
				paddingBottomHeight: 0,
			};
		},
		created() {
			let that = this;
			uni.getSystemInfo({
				success: function(res) {
					let model = ['X', 'XR', 'XS', '11', '12', '13', '14', '15'];
					model.forEach(item => {
						if (res.model.indexOf(item) != -1 && res.model.indexOf('iPhone') != -1) {
							that.paddingBottomHeight = 40;
						}
					});
				}
			});
		},
		methods: {
			changeTab(url) {
				uni.switchTab({
					url
				})
			},
			scan() {
				// #ifdef H5
				this.toast('请使用手机端进行此操作')
				// #endif
				// #ifdef APP-PLUS
				uni.scanCode({
					hideAlbum: true,
					onlyFromCamera: true,
					success: (res) => {
						var info = JSON.parse(res.result);
						console.log(info);
						if(info.type == 'course') {
							this.$to(`/pages/Write-off/Write-off?id=${info.order_id}`);
						}else if(info.type == 'public') {
							this.getCheck(info.order_id);
						}
					}
				})
				// #endif
				
			},
			async getCheck(order_id) {
				let shop_id = uni.getStorageSync('shopId');
				let res = await this.$api.post('staff/order/check', {
					order_id,
					times: 1,
					shop_id,
					type: 'public',
				});
				console.log('确认核销数据：',res);
				if(res.code == 200) {
					// console.log('确认核销数据：',res);
					uni.showToast({
						title: res.msg
					});
				}
			}
			
		}
	}
</script>

<style>
.tabbar {
	z-index: 99999;
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	display: flex;
	justify-content: space-around;
	align-items: center;
	width: 100%;
	height: 120rpx;
	background-color: #ffffff;
	border-top: 1rpx solid #f4f4f4;
}
.tabbar-item {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	height: 120rpx;
}
.item-img {
	margin-bottom: 4rpx;
	width: 44rpx;
	height: 44rpx;
}
.item-name {
	font-size: 24rpx;
	color: #555;
}
.tabbarActive {
	color: #F17816 !important;
}
.item-scan {
	width: 153rpx;
	height: 153rpx;
	margin: 0 -40rpx;
	margin-top: -80rpx;
	/* background-color: #000; */
	border-radius: 50%;
}
</style>